/*****************************************************************************

File:   otkDeleteCombinedStateExample.java

Date          Build     Author        Version    Comments
18-Sep-12    P-20-14    dshah          $$1        Created
18-Oct-12    P-20-15    dshah          $$2        Updated
20-mar-15 P-30-05 gshmelev $$3  called GetCurrentSession

****************************************************************************/

/* 
   
This example will work on the current Solid (Model/Assembly) as input and do the following: 
- Delete combined state: Asks user to enter number refering to "Existing combined Stated" from the list and 
deleted that combined state.

*/

package com.ptc.otkjavaexamples;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSolid.*;
import com.ptc.wfc.wfcCombState.*;


// Deletes Combined state

class otkDeleteCombinedStateExample extends DefaultUICommandActionListener
{
    
    
    
    public otkDeleteCombinedStateExample()
    {
    }
    
    
    
    
    public void OnCommand()
    {
	addDeleteCombinedStateExample();
    }
    
    
    public int addDeleteCombinedStateExample()
    {
	try
	    {
		FileWriter file = new FileWriter ("CombState_info.txt");
		BufferedWriter fp_out_combstate = new BufferedWriter(file);
		
		Session session = pfcSession.GetCurrentSession ();
		WSolid WSolid = (WSolid)(session.GetCurrentModel());
		
		CombStates WCombStates1 =   WSolid.ListCombStates();
		int CombStatesArraySize1 = WCombStates1.getarraysize ();
		
		fp_out_combstate.write("===========================");
		fp_out_combstate.newLine();
		fp_out_combstate.write("- Combined State Example -");
		fp_out_combstate.newLine();
		fp_out_combstate.write("===========================");
		fp_out_combstate.newLine();
		
		
		CombState WCombState = otkCombStateUtils.otkUtilSelectCombinedState (WSolid,(int)  -1);
		
		fp_out_combstate.write("**** Before Deleting Combined State ****");
		fp_out_combstate.newLine();
		fp_out_combstate.newLine();
		fp_out_combstate.write("List of Combined states:");
		fp_out_combstate.newLine();
		fp_out_combstate.newLine();
		
		for(int i=0; i<CombStatesArraySize1; i++)
		{
			CombState WCombState1 = WCombStates1.get(i);
			fp_out_combstate.write("-" + WCombState1.GetName());
			fp_out_combstate.newLine();
		}
		
		if(WCombState != null)
		    WSolid.DeleteCombState(WCombState);
			
		CombStates WCombStates2 =   WSolid.ListCombStates();
		int CombStatesArraySize2 = WCombStates2.getarraysize ();
		
		fp_out_combstate.newLine();
		fp_out_combstate.write("**** After Deleting Combined State ****");
		fp_out_combstate.newLine();
		fp_out_combstate.newLine();
		fp_out_combstate.write("List of Combined states:");
		fp_out_combstate.newLine();
		fp_out_combstate.newLine();		
		
		for(int i=0; i<CombStatesArraySize1; i++)
		{
			CombState WCombState1 = WCombStates1.get(i);
			fp_out_combstate.write("-" + WCombState1.GetName());
			fp_out_combstate.newLine();
		}
		
		fp_out_combstate.close();
		return (0);
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
	return (0);
    }
    
};






